{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from metadsl import *\n",
    "from metadsl_visualize import *\n",
    "import typing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "@expression\n",
    "def a(i):\n",
    "    ...\n",
    "\n",
    "@expression\n",
    "def b(i, j):\n",
    "    ...\n",
    "\n",
    "\n",
    "@expression\n",
    "def c(i):\n",
    "    ...\n",
    "\n",
    "\n",
    "@expression\n",
    "def g():\n",
    "    ...\n",
    "\n",
    "@expression\n",
    "def d(i):\n",
    "    ...\n",
    "\n",
    "@expression\n",
    "def e():\n",
    "    ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": {
       "nodes": {
        "-6767862926720903859": [
         "-6767862926720903859",
         {
          "args": [
           "7487258281850949799"
          ],
          "function": "d"
         }
        ],
        "4631586996325401013": [
         "4631586996325401013",
         {
          "function": "g"
         }
        ],
        "5036687493053654311": [
         "5036687493053654311",
         {
          "args": [
           "791240878759783297",
           "-6767862926720903859"
          ],
          "function": "b"
         }
        ],
        "6435859496084126448": [
         "6435859496084126448",
         {
          "args": [
           "5036687493053654311"
          ],
          "function": "a"
         }
        ],
        "7487258281850949799": [
         "7487258281850949799",
         {
          "function": "e"
         }
        ],
        "791240878759783297": [
         "791240878759783297",
         {
          "args": [
           "4631586996325401013"
          ],
          "function": "c"
         }
        ]
       },
       "states": {
        "initial": "6435859496084126448"
       }
      },
      "application/x.typez.graph+json": {
       "initial": "digraph {\n\tnode [shape=plain]\n\tedge [arrowsize=0.5 penwidth=0.5]\n\t6435859496084126448 [label=a id=6435859496084126448]\n\t6435859496084126448 -> 5036687493053654311 [id=\"6435859496084126448.args[0]\"]\n\t5036687493053654311 [label=b id=5036687493053654311]\n\t5036687493053654311 -> 791240878759783297 [id=\"5036687493053654311.args[0]\"]\n\t791240878759783297 [label=c id=791240878759783297]\n\t791240878759783297 -> 4631586996325401013 [id=\"791240878759783297.args[0]\"]\n\t4631586996325401013 [label=g id=4631586996325401013]\n\t5036687493053654311 -> -6767862926720903859 [id=\"5036687493053654311.args[1]\"]\n\t-6767862926720903859 [label=d id=-6767862926720903859]\n\t-6767862926720903859 -> 7487258281850949799 [id=\"-6767862926720903859.args[0]\"]\n\t7487258281850949799 [label=e id=7487258281850949799]\n}",
       "states": []
      },
      "text/plain": [
       "Typez(definitions=None, nodes={'4631586996325401013': ['4631586996325401013', CallNode(function='g', type_params=None, args=None, kwargs=None)], '791240878759783297': ['791240878759783297', CallNode(function='c', type_params=None, args=['4631586996325401013'], kwargs=None)], '7487258281850949799': ['7487258281850949799', CallNode(function='e', type_params=None, args=None, kwargs=None)], '-6767862926720903859': ['-6767862926720903859', CallNode(function='d', type_params=None, args=['7487258281850949799'], kwargs=None)], '5036687493053654311': ['5036687493053654311', CallNode(function='b', type_params=None, args=['791240878759783297', '-6767862926720903859'], kwargs=None)], '6435859496084126448': ['6435859496084126448', CallNode(function='a', type_params=None, args=['5036687493053654311'], kwargs=None)]}, states=States(initial='6435859496084126448', states=None))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "a(b(c(g()), d(e())))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": {
       "nodes": {
        "-422576679025410491": [
         "5036687493053654311",
         {
          "args": [
           "791240878759783297",
           "4153548277230129356"
          ],
          "function": "b"
         }
        ],
        "-6767862926720903859": [
         "-6767862926720903859",
         {
          "args": [
           "7487258281850949799"
          ],
          "function": "d"
         }
        ],
        "-8668826631765810444": [
         "6435859496084126448",
         {
          "args": [
           "-422576679025410491"
          ],
          "function": "a"
         }
        ],
        "4153548277230129356": [
         "-6767862926720903859",
         {
          "args": [
           "4631586996325401013"
          ],
          "function": "d"
         }
        ],
        "4631586996325401013": [
         "4631586996325401013",
         {
          "function": "g"
         }
        ],
        "5036687493053654311": [
         "5036687493053654311",
         {
          "args": [
           "791240878759783297",
           "-6767862926720903859"
          ],
          "function": "b"
         }
        ],
        "6435859496084126448": [
         "6435859496084126448",
         {
          "args": [
           "5036687493053654311"
          ],
          "function": "a"
         }
        ],
        "7487258281850949799": [
         "7487258281850949799",
         {
          "function": "e"
         }
        ],
        "791240878759783297": [
         "791240878759783297",
         {
          "args": [
           "4631586996325401013"
          ],
          "function": "c"
         }
        ]
       },
       "states": {
        "initial": "6435859496084126448",
        "states": [
         {
          "node": "-8668826631765810444",
          "rule": "Change"
         }
        ]
       }
      },
      "application/x.typez.graph+json": {
       "initial": "digraph {\n\tnode [shape=plain]\n\tedge [arrowsize=0.5 penwidth=0.5]\n\t6435859496084126448 [label=a id=6435859496084126448]\n\t6435859496084126448 -> 5036687493053654311 [id=\"6435859496084126448.args[0]\"]\n\t5036687493053654311 [label=b id=5036687493053654311]\n\t5036687493053654311 -> 791240878759783297 [id=\"5036687493053654311.args[0]\"]\n\t791240878759783297 [label=c id=791240878759783297]\n\t791240878759783297 -> 4631586996325401013 [id=\"791240878759783297.args[0]\"]\n\t4631586996325401013 [label=g id=4631586996325401013]\n\t5036687493053654311 -> -6767862926720903859 [id=\"5036687493053654311.args[1]\"]\n\t-6767862926720903859 [label=d id=-6767862926720903859]\n\t-6767862926720903859 -> 7487258281850949799 [id=\"-6767862926720903859.args[0]\"]\n\t7487258281850949799 [label=e id=7487258281850949799]\n}",
       "states": [
        {
         "graph": "digraph {\n\tnode [shape=plain]\n\tedge [arrowsize=0.5 penwidth=0.5]\n\t-8668826631765810444 [label=a id=6435859496084126448]\n\t-8668826631765810444 -> -422576679025410491 [id=\"6435859496084126448.args[0]\"]\n\t-422576679025410491 [label=b id=5036687493053654311]\n\t-422576679025410491 -> 791240878759783297 [id=\"5036687493053654311.args[0]\"]\n\t791240878759783297 [label=c id=791240878759783297]\n\t791240878759783297 -> 4631586996325401013 [id=\"791240878759783297.args[0]\"]\n\t4631586996325401013 [label=g id=4631586996325401013]\n\t-422576679025410491 -> 4153548277230129356 [id=\"5036687493053654311.args[1]\"]\n\t4153548277230129356 [label=d id=-6767862926720903859]\n\t4153548277230129356 -> 4631586996325401013 [id=\"-6767862926720903859.args[0]\"]\n}",
         "label": null,
         "rule": "Change"
        }
       ]
      },
      "text/plain": [
       "Typez(definitions=None, nodes={'4631586996325401013': ['4631586996325401013', CallNode(function='g', type_params=None, args=None, kwargs=None)], '791240878759783297': ['791240878759783297', CallNode(function='c', type_params=None, args=['4631586996325401013'], kwargs=None)], '7487258281850949799': ['7487258281850949799', CallNode(function='e', type_params=None, args=None, kwargs=None)], '-6767862926720903859': ['-6767862926720903859', CallNode(function='d', type_params=None, args=['7487258281850949799'], kwargs=None)], '5036687493053654311': ['5036687493053654311', CallNode(function='b', type_params=None, args=['791240878759783297', '-6767862926720903859'], kwargs=None)], '6435859496084126448': ['6435859496084126448', CallNode(function='a', type_params=None, args=['5036687493053654311'], kwargs=None)], '4153548277230129356': ['-6767862926720903859', CallNode(function='d', type_params=None, args=['4631586996325401013'], kwargs=None)], '-422576679025410491': ['5036687493053654311', CallNode(function='b', type_params=None, args=['791240878759783297', '4153548277230129356'], kwargs=None)], '-8668826631765810444': ['6435859496084126448', CallNode(function='a', type_params=None, args=['-422576679025410491'], kwargs=None)]}, states=States(initial='6435859496084126448', states=[State(node='-8668826631765810444', rule='Change', label=None)]))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ref = ExpressionReference.from_expression(a(b(c(g()), d(e()))))\n",
    "display = ExpressionDisplay(ref)\n",
    "\n",
    "ref.replace(a(b(c(g()), d(g()))))\n",
    "display.update(\"Change\")\n",
    "\n",
    "display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
